package colibri.lcdui;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;

/**
 * @author Bayron Thiengo Quinelato
 */
abstract class Item {

    boolean visible;
    boolean focus;
    boolean focusable;
    int width, height;
    int x, y, anchor;
    private int initialX, initialY;
    private Canvas canvas;
    String label;

    private boolean scrollsable;

    public Item(int x, int y, int width, int height, int anchor) {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
        this.anchor = anchor;

        initialX = x;
        initialY = y;
        visible = true;
        focus = false;
        focusable = true;
        scrollsable = true;
    }

    public Item(int x, int y, int width, int height) {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
        this.anchor = 0;

        initialX = x;
        initialY = y;
        visible = true;
        focus = false;
        focusable = true;
    }

    public void repaint() {
        if (canvas != null && width > 0 && height > 0) {
            canvas.repaint();
        }
    }

    abstract void callPaint(Graphics g);

    protected void callKeyPressed(int keyCode) {
    }

    protected void callKeyReleased(int keyCode) {
    }

    protected void callKeyRepeated(int keyCode) {
    }

    protected void callPointerPressed(int x, int y) {
    }

    protected void callPointerReleased(int x, int y) {
    }

    protected void callPointerDragged(int x, int y) {
    }

    void setVisible(boolean visible) {
        this.visible = visible;
        if (!visible) {
            this.focus = visible;
        }
    }

    public int getWidth(){
        return width;
    }

    public void setWidth(int width){
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height){
        this.height = height;
    }

    public void setX(int x) {
        this.x = x;
        initialX = x;
    }

    public int getX(){
        return x;
    }

    public void setY(int y) {
        this.y = y;
        initialY = y;
    }

    public int getY() {
        return y;
    }

    public int getInitialX(){
        return initialX;
    }

    public int getInitialY() {
        return initialY;
    }

    public void setScrollableX(int y) {
        this.y = y;
    }

    public void setScrollableY(int y) {
        this.y = y;
    }

    public void setScrollsable(boolean scrollsable) {
        this.scrollsable = scrollsable;
    }

    public boolean isScrollsable() {
        return this.scrollsable;
    }

    public Canvas getCanvas() {
        return canvas;
    }

    public void setCanvas(Canvas canvas) {
        this.canvas = canvas;
    }
}
